#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void* beancounter(void* beans_arg)
{
    int counter;
    int* beans = (int*)beans_arg;
    
    for (counter = 0; counter < 100000; counter++) {
        (*beans)++;    
    }
    return beans_arg;
}

int main(void)
{
    pthread_t t_beancounter0, t_beancounter1;
    int beans = 0;
    
    pthread_create(&t_beancounter0, 0, beancounter, (void*)(&beans));
    pthread_create(&t_beancounter1, 0, beancounter, (void*)(&beans));
    pthread_join(t_beancounter0, 0);
    pthread_join(t_beancounter1, 0);
    
    printf("The sum of all beans is %d\n", beans);
    return 0;
}
